package com.moussa.mike;

import android.content.Intent;
import android.net.Uri;

public class YouTubeVideo {

	private String title;
	private String author;
	private int duration;
	private long views;	// view count
	private long favorites;	// favorite count
	private float rating;	// rating (0 through 5)
	private String url; // url for youtube video
	private String categoryLabel; // url for youtube video
	private String categoryName; // url for youtube video
	private Intent intent; // intent to fire youtube app
	private Intent cintent; // intent to fire youtube channel

	private float captionRating;


	public YouTubeVideo(String title, String author, int duration, float rating, String url, long views, long favorites, String categoryLabel, String categoryName, int totalUserCaptionCount, int totalUserCount){
		this.title = title;
		this.author = author;
		this.duration = duration;
		this.rating = rating;
		this.url = url;
		this.views = views;
		this.favorites = favorites;
		this.intent = setVideoIntent(url);
		this.captionRating = (float)totalUserCaptionCount / (float)totalUserCount;
	}
	public YouTubeVideo(String title, String author, int duration, float rating, String url, long views, long favorites, String categoryLabel, String categoryName){
		this.title = title;
		this.author = author;
		this.duration = duration;
		this.rating = rating;
		this.url = url;
		this.views = views;
		this.favorites = favorites;
		this.intent = setVideoIntent(url);
		this.cintent = setVideoIntent(String.format("http://www.youtube.com/user/%s", author));
		this.captionRating = -1;
	}
	public void setUserCounts(int totalUserCaptionCount, int totalUserCount)
	{
		this.captionRating = (float)totalUserCaptionCount / (float)totalUserCount;
	}
	private Intent setVideoIntent(String url){
		Uri uri = Uri.parse(url);
		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_VIEW);
		intent.setData(uri);
		return intent;
	}

	public String getCategoryName(){
		return categoryName;
	}
	public String getCategoryLabell(){
		return categoryLabel;
	}
	public String getUrl(){
		return url;
	}

	public String getAuthor() {
		return author;
	}

	public String getTitle() {
		return title;
	}

	public float getUserRating(){
		return rating;
	}

	public float getCaptionRating(){
		return captionRating * 100;
	}

	public long getViewCount(){
		return views;
	}

	public long getFavoriteCount(){
		return favorites;
	}

	public int getDuration() {
		return duration;
	}
	public String getDurationString() {
		//int days = duration / (60*60*24);
		int aDuration = duration;
		int hours = aDuration / (60*60);
		aDuration = aDuration % (60*60);
		int minutes = aDuration / (60);
		aDuration = aDuration % (60);

		return String.format("%02d:%02d:%02d",hours,minutes, aDuration);
	}

	public Intent getVideoIntent(){	
		return intent;
	}

	public Intent getChannelIntent(){	
		return cintent;
	}


}
